package cn.seaboot.admin.reverse.web;

import cn.seaboot.admin.mvc.argument.Params;
import cn.seaboot.admin.reverse.bean.CodeTemplate;
import cn.seaboot.admin.reverse.service.CodeTplService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * 代码模版 [t_db_tpl] - Controller
 * <p>
 *
 * @author Mr.css on 2018-6-20
 */
@Controller
@Tag(name = "代码模版 [t_db_tpl] 管理")
@RequestMapping("db/tpl")
public class CodeTplCtrl {

    @Resource
    private CodeTplService tplService;

    /**
     * 增
     *
     * @param pojo pojo
     * @return affected rows
     */
    @ResponseBody
    @Operation(description = "代码模版 [t_db_tpl] 增")
    @RequestMapping(value = "info", method = RequestMethod.POST)
    public int saveInfo(@Validated CodeTemplate pojo) {
        return tplService.insert(pojo);
    }

    /**
     * 删
     *
     * @param id id
     * @return affected rows
     */
    @ResponseBody
    @Operation(description = "代码模版 [t_db_tpl] 删")
    @RequestMapping(value = "info", method = RequestMethod.DELETE)
    public int deleteInfo(@Params String id) {
        return tplService.deleteById(id);
    }

    /**
     * 查
     *
     * @param id id
     * @return pojo
     */
    @ResponseBody
    @Operation(description = "代码模版 [t_db_tpl] 查")
    @RequestMapping(value = "info", method = RequestMethod.GET)
    public CodeTemplate queryById(@Params String id) {
        return tplService.queryById(id);
    }

    /**
     * 改
     *
     * @param pojo pojo
     * @return affected rows
     */
    @ResponseBody
    @Operation(description = "代码模版 [t_db_tpl] 改")
    @RequestMapping(value = "info", method = RequestMethod.PUT)
    public int updateInfo(@Validated CodeTemplate pojo) {
        return tplService.updateById(pojo);
    }

    /**
     * 查列表
     *
     * @return listMap
     */
    @ResponseBody
    @Operation(description = "代码模版 [t_db_tpl] 列表查询")
    @RequestMapping(value = "list", method = RequestMethod.GET)
    public List<CodeTemplate> queryList() {
        return tplService.queryList();
    }
}